const con = require("./data.js")
const config = require('./config.js')

//
var imap = {
    // route 路由方法
    service: async function (uri, body) {
        let mp = config.mapper[uri];
        console.log('mapper req param is ->', JSON.stringify(mp));
        var resd = await execute(mp.sql, mp.param(body));
        console.log('mapper return data is ->', JSON.stringify(resd));
        return resd;
    }

}

// 根据sql查询返回
async function execute(sql, param) {
    try{
        return await con.dml(sql, param);
    }catch(e){
        console.error("数据库请求异常",e)
        return [];
    }
   
}

module.exports = imap;

